'use strict';

const Service = require('egg').Service;
class HomeService extends Service {
  // 登陆
  async login() {
    const createRule = {
      username: 'string',
      password: { type: 'string', require: true },
    };
    this.ctx.validate(createRule, this.ctx.request.body);
    const { username, password } = this.ctx.request.body;
    const data = await this.app.mysql.query(`select * from users where username=? and password=?`, [username, password])
    return data;
  }

  // 注册
  async register() {
    this.ctx.body = 'register'
  }

  // 查询
  async findAll() {
    const data = await this.app.mysql.query(`select * from users`);
    return data;
  }

  // 查询url 
  async findUrl() {
    const data = await this.app.mysql.query(`select titleurl from permissions where userid=?`, [this.ctx.state.user.userid]);
    return data;
  }
}

module.exports = HomeService;
